<?php
session_start();
ob_start();
$host="localhost";
$username="root";
$password="";
$database="cs4400_group17";

mysql_connect($host,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");

$username = $_SESSION['userName'];
$useremail = $_SESSION['userEmail'];

$sqlOne = "SELECT Tag, COUNT( DISTINCT URL ) , COUNT(DISTINCT myJoin.Title) FROM Tags  NATURAL JOIN (corkboard JOIN pushpin AS myjoin) GROUP BY Tag ORDER BY COUNT( * ) DESC  LIMIT 0 , 5;"; 
$resultOne = mysql_query($sqlOne);
	

?>
	<table width="400" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
		<tr>
			<td>Tag</td>
			<td>PushPins</td>
			<td>Unique Corkboards</td>
		</tr>
	</table>
<?php
while ($rows = mysql_fetch_array($resultOne)){
?>

	<table width="400" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
		<tr>
			<td><?php echo '<a href="searchPushpin.php?description=&corkBoardTitle=&tags='.$rows[0].'">'.$rows[0].'</a>'.', ';?></td>
			<td><?php echo $rows[1]?></td>
			<td><?php echo $rows[2]?></td>
			
		</tr>
	</table>
<?php
			}
			mysql_close();
		
			$count=mysql_num_rows($resultOne);
			
			if($count < 1){
				echo "<p>No Pushpins to match your search! Sowwy! :(</p>";
			}
?>